package com.ruoyi.lvlian.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.lvlian.domain.Weigh;
import com.ruoyi.lvlian.service.IWeighService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 过磅单Controller
 *
 * @author liyuxi
 * @date 2025-06-06
 */
@Api(value = "过磅单", tags = "过磅单Controller")
@RestController
@RequestMapping("/weigh")
public class WeighController extends BaseController {
    @Autowired
    private IWeighService weighService;

    /**
     * 查询过磅单列表
     */
//    @RequiresPermissions("lvlian:weigh:list")
    @GetMapping("/list")
    public TableDataInfo list(Weigh weigh) {
        startPage();
        List<Weigh> list = weighService.selectWeighList(weigh);
        return getDataTable(list);
    }


    /**
     * 获取过磅单详细信息
     */
//    @RequiresPermissions("lvlian:weigh:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(weighService.selectWeighById(id));
    }

    /**
     * 修改过磅单
     */
//    @RequiresPermissions("lvlian:weigh:edit")
    @Log(title = "过磅单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody  @Validated Weigh weigh) {
        return toAjax(weighService.updateWeigh(weigh));
    }

    /**
     * 删除过磅单
     */
//    @RequiresPermissions("lvlian:weigh:remove")
    @Log(title = "过磅单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(weighService.deleteWeighByIds(ids));
    }
}
